package com._520it.util;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class MybatisUtil {
	private static SqlSessionFactory factory;

	private MybatisUtil() {}

	static {
		InputStream inputStream;
		try {
			inputStream = Resources.getResourceAsStream("mybaties-config.xml");
			factory = new SqlSessionFactoryBuilder().build(inputStream);
		} catch (IOException e) {
			e.printStackTrace();

		}
	}

	// 获取sql执行Sqlsession
	public static SqlSession getSession() {
		return factory.openSession();
	}
}
